﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;

namespace OverStore.Runtime.CollectionPersisting
{
    /// <summary>
    /// Provide interface for classes that persist collection of different types.
    /// The actual supported collection class is determined by implementation.
    /// The way how collection are persisted is not depended of item type, so
    /// you may create instance of class implements this interface for each required instance type.
    /// </summary>
    /// <typeparam name="TInstance">The type of the instance.</typeparam>
    public interface ICollectionPersister<TInstance>
        where TInstance : class
    {
        /// <summary>
        /// Returns <c>true</c> if implementation can persists collection of specified type, <c>false</c> otherwise.
        /// </summary>
        bool SupportCollectionPersisting(IEnumerable<TInstance> collection);

        /// <summary>
        /// Clears the collection and fills it again using items extracted from parameterless reader.
        /// </summary>
        void Reload(IEnumerable<TInstance> collection);

        /// <summary>
        /// Clears the collection and fills it again using items extracted from parameterized reader with specified parameters.
        /// </summary>
        void Reload<TParameter>(IEnumerable<TInstance> collection, TParameter parameter)
            where TParameter : class;

        /// <summary>
        /// Saves the each item in specified collection, including items were deleted from collection, if they can be determined.
        /// </summary>
        void Save(IEnumerable<TInstance> collection);

        /// <summary>
        /// Adds the content of specified collection to session.
        /// </summary>
        /// <param name="collection">The collection.</param>
        void Add(IEnumerable<TInstance> collection);

        /// <summary>
        /// Marks every item in collection as deleted.
        /// </summary>
        void MarkAsDeleted(IEnumerable<TInstance> collection);

        /// <summary>
        /// Attaches each instance of specified collection, including deleted items if can be determined.
        /// </summary>
        IEnumerable<TInstance> Attach(IEnumerable<TInstance> collection);        
    }
}
